#ifndef DATA_TYPE_H
#define DATA_TYPE_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include <cjson/cJSON.h>
#include <pthread.h>
#define INFO_LEN 40
//通过MQTT上传数据的设备类型定义
#define BRIDGE_INFO_UPDATE_1         "01"
#define BRIDGE_INFO_UPDATE_2         "05"
#define IOT_TERMINAL_UPDATE          "02"
#define WIRELESS_4G_UPDATE           "03"

typedef char update_info_t[INFO_LEN];

typedef struct
{
    char *device;
    int speed;
    int energy_type;
} EnergyCfg;
extern EnergyCfg energyCfg;

///MPPT电池信息
typedef struct
{
    unsigned char  batteryCapacity;//电池剩余百分比,单位无，为整数，0~100

    float           columnVoltage;//阵列电压 V
    float           fArrayCur;//阵列电流 A
    char            columnStatus;//阵列状态

    float           batteryVoltage;//蓄电池电压 V
    float           batteryElectric;//蓄电池电流 A
    char            batteryStatus;//蓄电池状态

    unsigned short  sChargeStatus;//充电设备状态
    unsigned short  sDischargeStatus;//放电设备状态

    float           loadVoltage;//负载电压 V
    float           loadElectric;//负载电流 A
    float           loadPower;//负载功率 W
    char            loadStatus;//负载状态

    unsigned int    runDay;     //控制器运行天数
    unsigned int    lowVolCnt;  //欠压次数
    unsigned int    todayDischarge;   //今日放电量
    unsigned int    yesterdayDischarge;//昨日放电量
    unsigned long   totalDischarge;//总放电量
    unsigned int    todayCharge;//今日充电量
    unsigned int    yesterdayCharge;//昨日充电量
    unsigned long   totalCharge;//总充电量
    
    float           fDevTemperature;//控制器内部温度
    float           fBatTemperature;//电池内部温度，单位摄氏度
}StEnergyInfo;
extern StEnergyInfo stEnergyAck;//存储电池的数据

typedef struct
{
    unsigned char  s;//秒
    unsigned char  m;//分
    unsigned char  h;//时
    unsigned char  D;//日
    unsigned char  M;//月
    unsigned char  Y;//年
}StEpeverTime;
/*异构物联网通讯终端信息*/
typedef struct {
    update_info_t equipmentNumber;
    update_info_t equipmentType;
    /*基础数据（basicData）*/
    update_info_t startSettingTime;                 /*启动设置时间*/
    update_info_t sleepSettingTime;                 /*休眠设置时间*/
    update_info_t model;                    /*型号*/
    update_info_t softwareVersion;                  /*软件版本*/
    update_info_t ip;                   /*本地IP地址*/
    update_info_t gatewayIp;                    /*网关IP*/
    update_info_t netmask;                  /*网络掩码*/
    update_info_t locaMacAddress;                   /*本地mac地址*/
    update_info_t preferredDnsIp;                   /*首选DNS IP*/
    update_info_t alternateDnsIp;                   /*备用DNS IP*/
    /* 状态数据（statusData）*/
    update_info_t cpuUsage;                         /*CPU占用率*/
    update_info_t memoryUsage;      /*内存占用率*/
    update_info_t networkPortFlow;      /*网口流量*/
    update_info_t deviceCurrentTime;        /*设备当前时间*/
    /*电源状态数据（energySupplyStatusData）*/
    update_info_t equipmentTemperature;         /*设备温度*/
    update_info_t equipmentHumidity;            /*设备湿度*/
    update_info_t batteryTemperature;           /*电池温度*/
    update_info_t totalWorkingCurrent;          /*工作总电流*/
    update_info_t batteryVoltage;           /*电池电压*/
    update_info_t batteryLevel;         /*电池电量*/
    update_info_t chargingCurrent;          /*充电电流*/
    update_info_t chargingVoltage;          /*充电电压*/

    update_info_t runDay;     //控制器运行天数
    update_info_t lowVolCnt;  //欠压次数
    update_info_t todayDischarge;   //今日放电量
    update_info_t yesterdayDischarge;//昨日放电量
    update_info_t totalDischarge;//总放电量
    update_info_t todayCharge;//今日充电量
    update_info_t yesterdayCharge;//昨日充电量
    update_info_t totalCharge;//总充电量
    
    /*北斗模块（bdModuleData）*/
    update_info_t congitudeLatitude;        /*经纬度*/
    update_info_t altitude;                         /*海拔*/
    /* ZigBee模块数据（moduleData）*/
    update_info_t deviceMode;               /*设备模式*/
    update_info_t ZigBeeWorkingMode;                /*工作模式*/
    update_info_t localNetworkAddress;              /*本地网络短地址*/
    update_info_t moduleMacAddress;             /*模块MAC地址*/
    update_info_t zigBeewirelessChannel;                /*无线信道*/
    update_info_t transmitPower;                /*发射功率*/
    update_info_t ZigBeefirmwareVersion;                /*固件版本号*/
    /*LoRa模块数据（loRaModuleData）*/
    update_info_t loraModuleId;                     /*LORA模块ID*/
    update_info_t loraFirmwareversion;                      /*固件版本*/
    update_info_t loraWorkingMode;                      /*工作模式*/
    update_info_t loraSerialBaudRate;                       /*串口波特率*/
    update_info_t powerConsumptionMode;                     /*功耗模式*/
    update_info_t freeTime;                     /*空闲时间*/
    update_info_t wakeUpInterval;                       /*唤醒间隔*/
    update_info_t loraAirSpeed;                     /*LORA空中速率*/
    update_info_t destinationAddress;                       /*目标地址*/
    update_info_t wirelessChannel;                      /*无线信道*/
    update_info_t forwardErrorOrrection;                        /*前向纠错*/
    update_info_t loraTransmitPower;                        /*发射功率*/
    update_info_t snr;
    update_info_t rssi;
    /*链接信息数据（connectionInfo）*/
    update_info_t cameraOneStatus;                  /*连接摄像头1状态*/
    update_info_t cameraTwoStatus;                  /*连接摄像头2状态*/
    update_info_t bridgeOneStatus;                  /*连接网桥1状态*/
    update_info_t bridgeTwoStatus;                  /*连接网桥2状态*/
    update_info_t zigBeeTxIpAddress;                    /*连接传感器1（Zigbee）-发送方mac地址*/
    update_info_t sensorSendAddress;                    /*连接传感器1（Zigbee）-发送方短地址*/
    update_info_t sensorShortRssiValue;                 /*连接传感器1（Zigbee）-最短路径Rssi值*/
}IOT_TERMINAL;
#endif //DATA_TYPE_H
